﻿using System;

using System.Web.Security;
using He.Common;
using He.Web.UI;

namespace He.Web.user
{
    public partial class login : System.Web.UI.Page
    {
        InputUtil Input = new InputUtil();

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUserName.Text.Trim();
            string userpwd = txtUserPwd.Text.Trim();

            He.BLL.member mgr = new He.BLL.member();
            if (mgr.Exists(username, CryptoHelper.DESEncrypt(userpwd)))    //登录成功
            {
                He.Model.member member = mgr.GetModel(username);

                if (member.status == (int)Enums.MemberStatus.Email验证)
                {
                    Response.Redirect("/user/reg_check.aspx?status=" + Enums.MemberStatus.Email验证.ToString());
                    return;
                }
                if (member.status == (int)Enums.MemberStatus.人工审核)
                {
                    lblMsg.Text = "您的帐号尚未通过审核，需审核通过后才能登录";
                    return;
                }
                if (member.status == (int)Enums.MemberStatus.冻结)
                {
                    lblMsg.Text = "您的帐号已被冻结，请联系管理员！";
                    return;
                }
                else
                {
                    //登录处理
                    member.last_time = member.this_time;
                    member.this_time = DateTime.Now.ToString();
                    member.last_ip = member.this_ip;
                    member.this_ip = Request.UserHostAddress;
                    mgr.Update(member);

                    CookieHelper.Set("username", username);

                    //设置验证Cookie并跳转
                    FormsAuthentication.RedirectFromLoginPage(username, false);
                }
            }
            else
            {
                lblMsg.Text = "用户名或密码错误，请核对后重新输入";
                return;
            }
        }
    }
}